//
//  ServiceRemindRootViewController.m
//  CPICMobileServiceApp
//
//  Created by sinosoft on 13-2-27.
//  Copyright (c) 2013年 lizhiwei. All rights reserved.
//

#import "ServiceRemindRootViewController.h"
#import "ServiceRemindTableViewCell.h"
#import "RCAlertViewUtil.h"
#import "ASIHTTPRequest.h"
#import "Config.h"
#import "NSString+SBJson.h"
#import "NSObject+SBJson.h"
#import "RCAutoGlobal.h"
#import "UIImageView+WebCache.h"
#import "IFServiceEvaluation.h"
#import "Appdelegate.h"
#import "WSqlite.h"

@interface ServiceRemindRootViewController ()

@end

@implementation ServiceRemindRootViewController
@synthesize TableViewCar,TableViewInsurance;
@synthesize progress;

- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
    self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
    if (self) {
        // Custom initialization
        self.title=@"服务提醒设置";
        //self.view.backgroundColor = [UIColor colorWithPatternImage:[UIImage imageNamed:@"bg640X773@2x"]];
    }
    return self;
}

- (void)viewDidLoad
{
    [super viewDidLoad];
	// Do any additional setup after loading the view.
    NSUserDefaults *accountDefaults = [NSUserDefaults standardUserDefaults];
    NSString *bgimage= [accountDefaults objectForKey:@"UserDefaultBgKindKey"];
    
    if ([bgimage isEqualToString:@"蓝色主题风格"])
    {
        ADD_BACKGROUND_BUTTONITEM(@"icon640X88@2x.png");
        ADD_LEFT_BUTTONITEM(@"back.png");
        ADD_TITLE_NAMEITEM(@"服务提醒设置");
        self.view.backgroundColor = [UIColor colorWithPatternImage:[UIImage imageNamed:@"bg640X773@2x"]];
    }
    else if([bgimage isEqualToString:@"棕色主题风格"])
    {
        ADD_BACKGROUND_BUTTONITEM(@"icon640X88_01@2x.png");
        ADD_LEFT_BUTTONITEM(@"back_01.png");
        ADD_TITLE_NAMEITEM(@"服务提醒设置");
        self.view.backgroundColor = [UIColor colorWithPatternImage:[UIImage imageNamed:@"bg640X773_01@2x"]];
    }
    else if([bgimage isEqualToString:@"重大节日皮肤"])
    {
        NSData *dataImg_02=[[NSUserDefaults standardUserDefaults]objectForKey:SKIN_IMG_DATA_02];
        NSLog(@"-------找到%@",dataImg_02);
        NSData *dataImg_03=[[NSUserDefaults standardUserDefaults]objectForKey:SKIN_IMG_DATA_03];
        NSData *dataImg_04=[[NSUserDefaults standardUserDefaults]objectForKey:SKIN_IMG_DATA_04];
        
        NSURL *urlSkinImg_02=[NSURL URLWithString:[[NSUserDefaults standardUserDefaults]objectForKey:SKIN_IMG_URL_02]];
        NSURL *urlSkinImg_03=[NSURL URLWithString:[[NSUserDefaults standardUserDefaults]objectForKey:SKIN_IMG_URL_03]];
        NSURL *urlSkinImg_04=[NSURL URLWithString:[[NSUserDefaults standardUserDefaults]objectForKey:SKIN_IMG_URL_04]];
        NSLog(@"-------找到333%@",urlSkinImg_02);
        
        UIImageView * LogoImage = [[UIImageView alloc]init];
        [LogoImage setImageWithURL:urlSkinImg_03 success:^(UIImage *image)
         {
             NSData *imgData=UIImagePNGRepresentation(LogoImage.image);
             [[NSUserDefaults standardUserDefaults] setObject:imgData forKey:SKIN_IMG_DATA_03];
         } failure:^(NSError *error)
         {
             [self justShowMessage:@"更新皮肤失败!" title:@"提示"];
         }];
        
        LogoImage.image = [UIImage imageWithData:dataImg_03];
        LogoImage.frame = CGRectMake(0, 0, LogoImage.image.size.width/2, LogoImage.image.size.height/2);
        [self.view addSubview:LogoImage];
        
        //--------------------------
        UIButton * CallOutBtn1 = [UIButton buttonWithType:UIButtonTypeCustom];
        CallOutBtn1.frame = CGRectMake(10, 10, 109/2, 57/2);
        UIImageView * Back = [[UIImageView alloc]init];
        [Back setImageWithURL:urlSkinImg_02 success:^(UIImage *image)
         {
             NSData *imgData=UIImagePNGRepresentation(Back.image);
             [[NSUserDefaults standardUserDefaults] setObject:imgData forKey:SKIN_IMG_DATA_02];
         } failure:^(NSError *error)
         {
             [self justShowMessage:@"更新皮肤失败!" title:@"提示"];
         }];
        
        [Back setImage:[UIImage imageWithData:dataImg_02]];
        [CallOutBtn1 setImage:Back.image forState:UIControlStateNormal];
        [CallOutBtn1 addTarget:self action:@selector(ClickCallOutBtn) forControlEvents:UIControlEventTouchUpInside];
        [self.view addSubview:CallOutBtn1];
        //--------------------------
        
        ADD_TITLE_NAMEITEM(@"服务提醒设置");
        
        UIImageView *bgimage = [[UIImageView alloc]initWithFrame:CGRectMake(0,44, self.view.frame.size.width, self.view.frame.size.height-44)];
        [bgimage setImageWithURL:urlSkinImg_04 success:^(UIImage *image)
         {
             NSData *imgData=UIImagePNGRepresentation(bgimage.image);
             [[NSUserDefaults standardUserDefaults] setObject:imgData forKey:SKIN_IMG_DATA_04];
         } failure:^(NSError *error)
         {
             [self justShowMessage:@"更新皮肤失败!" title:@"提示"];
         }];
        
        [bgimage setImage:[UIImage imageWithData:dataImg_04]];
        [self.view addSubview:bgimage];
        [bgimage release];
    }

    //添加UITableview
    TableViewCar = [[UITableView alloc]initWithFrame:CGRectMake(0, 44, 320, 80) style:UITableViewStylePlain];
	TableViewCar.delegate = self;
	TableViewCar.dataSource = self;
    
    TableViewCar.opaque = NO;
    TableViewCar.backgroundView = nil;
    TableViewCar.autoresizingMask = UIViewContentModeTop;
    TableViewCar.autoresizingMask = UIViewAutoresizingFlexibleHeight|UIViewAutoresizingFlexibleWidth;
    TableViewCar.scrollEnabled=NO;
    //TableViewCar.backgroundColor=[UIColor clearColor];
    //[TableViewUser reloadData];
	[self.view addSubview:TableViewCar];
    
    
    TableViewInsurance = [[UITableView alloc]initWithFrame:CGRectMake(0, 124, 320, 200) style:UITableViewStylePlain];
	TableViewInsurance.delegate = self;
	TableViewInsurance.dataSource = self;
    
    TableViewInsurance.opaque = NO;
    TableViewInsurance.backgroundView = nil;
    TableViewInsurance.autoresizingMask = UIViewContentModeTop;
    TableViewInsurance.autoresizingMask = UIViewAutoresizingFlexibleHeight|UIViewAutoresizingFlexibleWidth;
    TableViewInsurance.scrollEnabled=NO;
    //TableViewInsurance.backgroundColor=[UIColor clearColor];
    //[TableViewPassword reloadData];
	[self.view addSubview:TableViewInsurance];
    
    arrCar=[[NSMutableArray alloc]init];
    arrInsurance=[[NSMutableArray alloc]init];
    arrSetListData=[[NSMutableArray alloc]init];
    
    UIButton *btnSubmit=[UIButton buttonWithType:UIButtonTypeCustom];
    btnSubmit.frame=CGRectMake(90, 400, 310/2, 119/2);
    [btnSubmit setBackgroundImage:[UIImage imageNamed:@"reg.png"] forState:UIControlStateNormal];
    [btnSubmit addTarget:self action:@selector(submitRemind) forControlEvents:UIControlEventTouchDown];
    [self.view addSubview:btnSubmit];
    UILabel *lblTitle=[[UILabel alloc]initWithFrame:CGRectMake(145, 407, 73, 21)];
    lblTitle.font=[UIFont systemFontOfSize:17.0];
    lblTitle.textColor=[UIColor whiteColor];
    lblTitle.backgroundColor=[UIColor clearColor];
    lblTitle.text=@"提交";
    [self.view addSubview:lblTitle];
    
    //[NSThread detachNewThreadSelector:@selector(getCarListInfo) toTarget:self withObject:nil];
    [self getCarListInfo];
    
    //[self setRemindListRequest];
    AppDelegate *myDelegate = [[UIApplication sharedApplication] delegate];
    myDelegate.bServiceRemind=FALSE;
    
    [self setEvaluationRequest];
}
-(void) ClickCallOutBtn
{
    AppDelegate *myDelegate = [[UIApplication sharedApplication] delegate];
    if (myDelegate.bServiceRemind==FALSE) {
        [self.navigationController popViewControllerAnimated:YES];
    }
    else
    {
        if ([Flag isEqualToString:@"0"])
        {
            [self IFServiceEvaluation];
            Flag = @"1";
        }
        else
        {
            [self.navigationController popViewControllerAnimated:YES];
        }
    }
}
-(void)getCarListInfo
{
    RCCarListInfo *rcCarListInfo=[[RCCarListInfo alloc]initCarListInfoView];
    rcCarListInfo.carInfoDelegate=self;
    [rcCarListInfo setCarListRequest:NO];
    [rcCarListInfo setHidden:YES];
    [self.view addSubview:rcCarListInfo];
    [rcCarListInfo release];
}
-(void)getCarListInfo:(BOOL)bCarInfo
{
    if (bCarInfo==YES) {
        hasCarInfo=YES;
    }
    else
    {
        hasCarInfo=NO;
    }
    [self setRemindListRequest];
}

-(void)setEvaluationRequest
{
    NSLog(@"==================");
    NSString *serviceid =@"60301";
    NSString *servicename =@"服务提醒设置";
    IFServiceEvaluation *ifserviceevaluation =[[IFServiceEvaluation alloc]initView:serviceid withserviceName:servicename];
    [ifserviceevaluation setIfServiceEvaluationRequest];
    [ifserviceevaluation setHidden:YES];
    [self.view addSubview:ifserviceevaluation];
    [ifserviceevaluation release];
}
-(void) IFServiceEvaluation
{
    NSString *serviceid =@"60301";
    NSString *servicename =@"服务提醒设置";
    NSUserDefaults *myDefaults=[NSUserDefaults standardUserDefaults];
    if ([myDefaults stringForKey:serviceid]) {
        NSString *strEvaluate=[myDefaults stringForKey:serviceid];
        if ([strEvaluate isEqualToString:@"1"]) {
            AddServiceEvaluationViewController *serviceevluation = [[AddServiceEvaluationViewController alloc]initView:serviceid withserviceName:servicename];
            [[AppDelegate app].unc pushViewController:serviceevluation animated:YES];
            [serviceevluation release];
        }
        else
        {
            [self.navigationController popToRootViewControllerAnimated:YES];
        }
    }
    else
    {
        [self.navigationController popToRootViewControllerAnimated:YES];
    }
}


-(void)setRemindListRequest//向太保移动平台发送请求报文
{
    NSLog(@"userinfodefault%@",[[NSUserDefaults standardUserDefaults] objectForKey:DICT_USER_INFO]);
    NSDictionary *dictUserInfo=[[NSUserDefaults standardUserDefaults] dictionaryForKey:DICT_USER_INFO];
    if (dictUserInfo!=nil) {
        if ([dictUserInfo valueForKey:@"UserAccount"]) {
            NSLog(@"%@",[dictUserInfo valueForKey:@"UserAccount"]);
        }
    }
    else
    {
        [self justShowMessage:@"用户还没登录,请登录系统" title:@"注意"];
        return;
    }
    
    WSqlite *sql =[WSqlite Instance];
    arrSetListData=[sql getServiceNoticeData:[dictUserInfo valueForKey:@"UserAccount"]];
    //if ([arrSetListData count]>0) {
    arrCar=[[NSMutableArray alloc]initWithObjects:@"车辆年检提醒",@"驾驶证年检提醒", nil];
    arrInsurance=[[NSMutableArray alloc]initWithObjects:@"理赔进度提醒",@"保单续保提醒",@"服务预约提醒",@"优惠信息提醒",@"秒杀信息提醒", nil];
        [TableViewCar reloadData];
        [TableViewInsurance reloadData];
   // }
   // else
   // {
        NSMutableDictionary *dicRequest = [NSMutableDictionary dictionary];
        //RCAutoGlobal *global=[RCAutoGlobal sharedRCAutoGlobal];
        
        NSString *userAccount=[dictUserInfo valueForKey:@"UserAccount"];
        if (userAccount.length!=0) {
            [dicRequest setObject:userAccount forKey:@"userAccount"];
        }
        else
        {
            [dicRequest setObject:userAccount forKey:@"userAccount"];
        }
        
        NSString *strRequestJson=[dicRequest JSONRepresentation];
        ASIFormDataRequest *request = [[ASIFormDataRequest alloc] initWithURL:[NSURL URLWithString:Server_Url_Form]];
        
        //设置需要POST的数据，这里提交两个数据，A=a&B=b
        [request setPostValue:@"50201" forKey:@"RequestCode"];
        [request setPostValue:strRequestJson forKey:@"RequestData"];
        
        [request setDelegate:self];
        [request setDidFailSelector:@selector(ResponseRemindListFail:)];
        [request setDidFinishSelector:@selector(ResonseRemindListSuccess:)];
        [request startAsynchronous];
        
        showProgress = YES;
        if (showProgress) {
            NSLog(@"88888");
            //[NSThread sleepForTimeInterval:1];
            progress= [[MBProgressHUD alloc]initWithView:self.view];
            [self.view addSubview:progress];
            [self.view bringSubviewToFront:progress];
            progress.labelText = @"查询中...";
            [progress show:YES];
            showProgress = NO;
        }
   // }
    
}

- (void)ResonseRemindListSuccess:(ASIHTTPRequest *)request
{
    Flag=@"0";
    if (!showProgress)
    {
        [progress removeFromSuperview];
        progress = nil;
    }
    NSString *responseString = [request responseString];
    NSLog(@"responseString %@",responseString);
    NSMutableDictionary *dictResponse=[responseString JSONValue];
    NSLog(@"dictResponse  %@",dictResponse);
    NSMutableDictionary *dictHead=[dictResponse valueForKey:@"head"];
    NSString *strResult= [[NSString alloc] initWithFormat:@"%@",[dictHead objectForKey:@"success"]];
    NSLog(@"strResult%@",strResult);
    arrSetListData=[dictResponse objectForKey:@"setList"];
    [strResult release];
    [TableViewCar reloadData];
    [TableViewInsurance reloadData];
    
    NSDictionary *dictUserInfo=[[NSUserDefaults standardUserDefaults] dictionaryForKey:DICT_USER_INFO];
    WSqlite *sql =[WSqlite Instance];
    [sql insertServiceNoticeData:arrSetListData withUserAccount:[dictUserInfo valueForKey:@"UserAccount"]];

    
}

- (void)ResponseRemindListFail:(ASIHTTPRequest *)request
{
    if (!showProgress)
    {
        [progress removeFromSuperview];
        progress = nil;
    }
    NSLog(@"服务器连接失败!");
    [self justShowMessage:@"服务器连接失败" title:@"注意"];
}

-(void)submitRemind
{
    AppDelegate *myDelegate = [[UIApplication sharedApplication] delegate];
    myDelegate.bServiceRemind=TRUE;
    [self setRequest];
}
-(void)setRequest//向太保移动平台发送请求报文
{
    NSLog(@"userinfodefault%@",[[NSUserDefaults standardUserDefaults] objectForKey:DICT_USER_INFO]);
    NSDictionary *dictUserInfo=[[NSUserDefaults standardUserDefaults] dictionaryForKey:DICT_USER_INFO];
    if (dictUserInfo!=nil) {
        if ([dictUserInfo valueForKey:@"UserAccount"]) {
            NSLog(@"%@",[dictUserInfo valueForKey:@"UserAccount"]);
        }
        else
        {
            [self justShowMessage:@"用户还没登录,请登录系统" title:@"注意"];
            return;
        }
    }
    else
    {
        [self justShowMessage:@"用户还没登录,请登录系统" title:@"注意"];
        return;
    }
    

    
    
//    NSString *strRequestCode=@"RequestCode=60301";
    NSMutableDictionary *dicRequest = [NSMutableDictionary dictionary];
    if(strCarInspection.length!=0)
    {
        [dicRequest setObject:strCarInspection forKey:@"carInspection"];
    }
    else
    {
        [dicRequest setObject:@"" forKey:@"carInspection"];
    }
    
    if(strlicenseInspection.length!=0)
    {
        [dicRequest setObject:strlicenseInspection forKey:@"licenseInspection"];
    }
    else
    {
        [dicRequest setObject:@"" forKey:@"licenseInspection"];
    }
    
    if(strTravelTax.length!=0)
    {
        [dicRequest setObject:strTravelTax forKey:@"travelTax"];
    }
    else
    {
        [dicRequest setObject:@"" forKey:@"travelTax"];
    }
    
    if(strClaimsProgress.length!=0)
    {
        [dicRequest setObject:strClaimsProgress forKey:@"claimsProgress"];
    }
    else
    {
        [dicRequest setObject:@"" forKey:@"claimsProgress"];
    }
    
    if(strPolicyRenewal.length!=0)
    {
        [dicRequest setObject:strPolicyRenewal forKey:@"policyRenewal"];
    }
    else
    {
        [dicRequest setObject:@"" forKey:@"policyRenewal"];
    }
    
    if (strServiceAppointment.length!=0) {
        [dicRequest setObject:strServiceAppointment forKey:@"serviceAppointment"];
    }
    else
    {
        [dicRequest setObject:@"" forKey:@"serviceAppointment"];
    }
    
    if (strPreferential.length!=0) {
        [dicRequest setObject:strPreferential forKey:@"offers"];
    }
    else
    {
        [dicRequest setObject:@"" forKey:@"offers"];
    }
    
    if (strSeckill.length!=0) {
        [dicRequest setObject:strSeckill forKey:@"seckill"];
    }
    else
    {
        [dicRequest setObject:@"" forKey:@"seckill"];
    }
    //RCAutoGlobal *global=[RCAutoGlobal sharedRCAutoGlobal];
    NSString *userAccount=[dictUserInfo valueForKey:@"UserAccount"];
    if (userAccount.length!=0) {
        [dicRequest setObject:userAccount forKey:@"userAccount"];
    }
    else
    {
        [dicRequest setObject:@"" forKey:@"userAccount"];
    }
    
    NSString *strRequestJson=[dicRequest JSONRepresentation];
//    strRequestJson=[NSString stringWithFormat:@"&RequestData=%@",strRequestJson];
//    NSString *strUrl=[NSString stringWithFormat:@"%@%@%@",Server_Url,strRequestCode,strRequestJson];
//    NSString *strUrlEncod = [strUrl stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding];//字符串编码转换
//    NSURL *myurl = [NSURL URLWithString:strUrlEncod];//This method expects URLString to contain any necessary percent escape codes, which are ‘:’, ‘/’, ‘%’, ‘#’, ‘;’, and ‘@’. Note that ‘%’ escapes are translated via UTF-8.
//    NSLog(@"请求报文为:%@",strUrl);
    ASIFormDataRequest *request = [[ASIFormDataRequest alloc] initWithURL:[NSURL URLWithString:Server_Url_Form]];
    
    //设置需要POST的数据，这里提交两个数据，A=a&B=b
    [request setPostValue:@"60301" forKey:@"RequestCode"];
    [request setPostValue:strRequestJson forKey:@"RequestData"];
    
    [request setDelegate:self];
    [request setDidFailSelector:@selector(ResponseFail:)];
    [request setDidFinishSelector:@selector(ResonseSuccess:)];
    [request startAsynchronous];
    
    showProgress = YES;
    if (showProgress) {
        NSLog(@"88888");
        //[NSThread sleepForTimeInterval:1];
        progress= [[MBProgressHUD alloc]initWithView:self.view];
        [self.view addSubview:progress];
        [self.view bringSubviewToFront:progress];
        progress.labelText = @"查询中...";
        [progress show:YES];
        showProgress = NO;
    }
}

- (void)ResonseSuccess:(ASIHTTPRequest *)request
{
    if (!showProgress)
    {
        [progress removeFromSuperview];
        progress = nil;
    }
    NSString *responseString = [request responseString];
    NSLog(@"responseString %@",responseString);
    NSMutableDictionary *dictResponse=[responseString JSONValue];
    NSLog(@"dictResponse  %@",dictResponse);
    NSMutableDictionary *dictHead=[dictResponse valueForKey:@"head"];
    NSString *strResult= [[NSString alloc] initWithFormat:@"%@",[dictHead objectForKey:@"success"]];
    NSLog(@"strResult%@",strResult);
    if ([strResult isEqualToString:@"1"]) {
        [self justShowMessage:@"保存成功" title:nil];
//        NSDictionary *dictUserInfo=[[NSUserDefaults standardUserDefaults] dictionaryForKey:DICT_USER_INFO];
//        WSqlite *sql =[WSqlite Instance];
//        [sql insertServiceNoticeData:arrSetListData withUserAccount:[dictUserInfo valueForKey:@"UserAccount"]];
    }
    else
    {
        [self justShowMessage:@"保存失败" title:nil];
    }
    [strResult release];
    
    
}

- (void)ResponseFail:(ASIHTTPRequest *)request
{
    if (!showProgress)
    {
        [progress removeFromSuperview];
        progress = nil;
    }
    NSLog(@"服务器连接失败!");
    [self justShowMessage:@"服务器连接失败" title:@"注意"];
}


#pragma UITableViewDelegate

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    if(tableView==TableViewCar)
    {
        return [arrCar count];
    }
    else
    {
        return [arrInsurance count];
    }
}


-(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
    return 40;
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    if(tableView==TableViewCar)
    {
        NSMutableDictionary *dictItem=[[NSMutableDictionary alloc]init];
        if ([arrSetListData count]>=6) {
            dictItem=[arrSetListData objectAtIndex:indexPath.row];
        }
        
        static NSString *Identifier=@"Identifier";
        ServiceRemindTableViewCell *cell=(ServiceRemindTableViewCell *)[TableViewCar dequeueReusableCellWithIdentifier:Identifier];
        if (cell==nil)
        {
            cell=[[[ServiceRemindTableViewCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:Identifier]autorelease];
            cell.accessoryType = UITableViewCellAccessoryNone;
            cell.selectionStyle = UITableViewCellSelectionStyleNone;
        }
        cell.lblName.text=[arrCar objectAtIndex:indexPath.row];
        cell.swcON.tag=indexPath.row;
        [cell.swcON addTarget:self action:@selector(setRemindCar:) forControlEvents:UIControlEventValueChanged];
        
        NSString *strOpen=[[NSString alloc]initWithFormat:@"%@",[dictItem objectForKey:@"open"]];
        if(indexPath.row==0)
        {

//            NSLog(@"DICT_CAR_INFO%@",[[NSUserDefaults standardUserDefaults] objectForKey:DICT_CAR_INFO]);
//            NSDictionary *dictUserInfo=[[NSUserDefaults standardUserDefaults] dictionaryForKey:DICT_CAR_INFO];
            if (hasCarInfo==YES)
            {
//                if (hasCarInfo==YES)
//                {
                    [cell.btnInfo setImage:[UIImage imageNamed:@"Set.png"] forState:UIControlStateNormal];
//                    NSLog(@"%@",[dictUserInfo valueForKey:@"license"]);
//                }
//                else
//                {
//
//                    cell.btnInfo.tag=indexPath.row;
//                    [cell.btnInfo addTarget:self action:@selector(setDetailInfo:) forControlEvents:UIControlEventTouchUpInside];
//                    [cell.btnInfo setImage:[UIImage imageNamed:@"UnSet.png"] forState:UIControlStateNormal];
//                }
            }
            else
            {
                cell.btnInfo.tag=indexPath.row;
                [cell.btnInfo addTarget:self action:@selector(setDetailInfo:) forControlEvents:UIControlEventTouchUpInside];
                [cell.btnInfo setImage:[UIImage imageNamed:@"UnSet.png"] forState:UIControlStateNormal];
            }
            if ([strOpen isEqualToString:@"1"]) {
                [cell.swcON setOn:YES];
                strCarInspection=@"1";
            }
            else if([strOpen isEqualToString:@"0"])
            {
                [cell.swcON setOn:NO];
                strCarInspection=@"0";
            }
            else
            {
                strCarInspection=@"";
            }
            
        }
        else if(indexPath.row==1)
        {

            [cell.btnInfo setImage:[UIImage imageNamed:@"Set.png"] forState:UIControlStateNormal];
            if ([strOpen isEqualToString:@"1"]) {
                [cell.swcON setOn:YES];
                strlicenseInspection=@"1";
            }
            else if([strOpen isEqualToString:@"0"])
            {
                [cell.swcON setOn:NO];
                strlicenseInspection=@"0";
            }
            else
            {
                strlicenseInspection=@"";
            }
        }
        else if(indexPath.row==2)
        {

//            NSLog(@"DICT_CAR_INFO%@",[[NSUserDefaults standardUserDefaults] objectForKey:DICT_CAR_INFO]);
//            NSDictionary *dictUserInfo=[[NSUserDefaults standardUserDefaults] dictionaryForKey:DICT_CAR_INFO];
            if (hasCarInfo==YES)
            {
//                if (hasCarInfo==YES)
//                {
                    [cell.btnInfo setImage:[UIImage imageNamed:@"Set.png"] forState:UIControlStateNormal];
//                    NSLog(@"%@",[dictUserInfo valueForKey:@"firstdate"]);
//                }
//                else
//                {
//                    cell.btnInfo.tag=indexPath.row;
//                    [cell.btnInfo addTarget:self action:@selector(setDetailInfo:) forControlEvents:UIControlEventTouchUpInside];
//                    [cell.btnInfo setImage:[UIImage imageNamed:@"UnSet.png"] forState:UIControlStateNormal];
//                }
            }
            else
            {
                cell.btnInfo.tag=indexPath.row;
                [cell.btnInfo addTarget:self action:@selector(setDetailInfo:) forControlEvents:UIControlEventTouchUpInside];
                [cell.btnInfo setImage:[UIImage imageNamed:@"UnSet.png"] forState:UIControlStateNormal];
            }

 
            if ([strOpen isEqualToString:@"1"]) {
                [cell.swcON setOn:YES];
                strTravelTax=@"1";
            }
            else if([strOpen isEqualToString:@"0"])
            {
                [cell.swcON setOn:NO];
                strTravelTax=@"0";
            }
            else
            {
                strTravelTax=@"";
            }
        }
        return cell;
    }
    else
    {
        NSMutableDictionary *dictItem=[[NSMutableDictionary alloc]init];
        if ([arrSetListData count]>=6) {
            dictItem=[arrSetListData objectAtIndex:indexPath.row+3];
        }
        static NSString *Identifier=@"Identifier";
        ServiceRemindTableViewCell *cell=(ServiceRemindTableViewCell *)[TableViewInsurance dequeueReusableCellWithIdentifier:Identifier];
        if (cell==nil)
        {
            cell=[[[ServiceRemindTableViewCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:Identifier]autorelease];
            cell.accessoryType = UITableViewCellAccessoryNone;
            cell.selectionStyle=UITableViewCellSelectionStyleNone;
        }
        cell.lblName.text=[arrInsurance objectAtIndex:indexPath.row];
        cell.swcON.tag=indexPath.row;
        [cell.swcON addTarget:self action:@selector(setRemindInsurance:) forControlEvents:UIControlEventValueChanged];
        NSString *strOpen=[[NSString alloc]initWithFormat:@"%@",[dictItem objectForKey:@"open"]];
        if(indexPath.row==0)
        {
            
            [cell.btnInfo setImage:[UIImage imageNamed:@"Set.png"] forState:UIControlStateNormal];
            if ([strOpen isEqualToString:@"1"]) {
                [cell.swcON setOn:YES];
                strClaimsProgress=@"1";
            }
            else if([strOpen isEqualToString:@"0"])
            {
                [cell.swcON setOn:NO];
                strClaimsProgress=@"0";
            }
            else
            {
                strClaimsProgress=@"";
            }
        }
        else if(indexPath.row==1)
        {
            
            [cell.btnInfo setImage:[UIImage imageNamed:@"Set.png"] forState:UIControlStateNormal];
            if ([strOpen isEqualToString:@"1"]) {
                [cell.swcON setOn:YES];
                strPolicyRenewal=@"1";
            }
            else if([strOpen isEqualToString:@"0"])
            {
                [cell.swcON setOn:NO];
                strPolicyRenewal=@"0";
            }
            else
            {
                strPolicyRenewal=@"";
            }
        }
        else if(indexPath.row==2)
        {

            
            [cell.btnInfo setImage:[UIImage imageNamed:@"Set.png"] forState:UIControlStateNormal];
            if ([strOpen isEqualToString:@"1"]) {
                [cell.swcON setOn:YES];
                strServiceAppointment=@"1";
            }
            else if([strOpen isEqualToString:@"0"])
            {
                [cell.swcON setOn:NO];
                strServiceAppointment=@"0";
            }
            else
            {
                strServiceAppointment=@"";
            }
        }
        else if(indexPath.row==3)
        {
            [cell.btnInfo setImage:[UIImage imageNamed:@"Set.png"] forState:UIControlStateNormal];
            if ([strOpen isEqualToString:@"1"]) {
                [cell.swcON setOn:YES];
                strPreferential=@"1";
            }
            else if([strOpen isEqualToString:@"0"])
            {
                [cell.swcON setOn:NO];
                strPreferential=@"0";
            }
            else
            {
                strPreferential=@"";
            }
        }
        else if(indexPath.row==4)
        {
            [cell.btnInfo setImage:[UIImage imageNamed:@"Set.png"] forState:UIControlStateNormal];
            if ([strOpen isEqualToString:@"1"]) {
                [cell.swcON setOn:YES];
                strSeckill=@"1";
            }
            else if([strOpen isEqualToString:@"0"])
            {
                [cell.swcON setOn:NO];
                strSeckill=@"0";
            }
            else
            {
                strSeckill=@"";
            }
        }
        
        return cell;
    }
    
    
}

-(void)setDetailInfo:(id)sender
{
    UIButton *btn=(UIButton *)sender;
    NSLog(@"%dtag",btn.tag);
    if (btn.tag==0) {
        [self justShowMessage:@"车牌号码不能为空,请到车辆设置页面去补充" title:@"注意"];
    }
    else if(btn.tag==2)
    {
        [self justShowMessage:@"车辆初登日期不能为空,请到车辆设置页面去补充" title:@"注意"];
    }
}

-(void)setRemindCar:(id)sender
{
    UISwitch *Switch=(UISwitch *)sender;
    //NSString *strTag=[NSString stringWithFormat:@"%d",Switch.tag];
    //[self justShowMessage:strTag title:@""];
    if(Switch.tag==0)
    {
//        NSLog(@"DICT_CAR_INFO%@",[[NSUserDefaults standardUserDefaults] objectForKey:DICT_CAR_INFO]);
//        NSDictionary *dictUserInfo=[[NSUserDefaults standardUserDefaults] dictionaryForKey:DICT_CAR_INFO];
        if (hasCarInfo==YES)
        {
//            if ([dictUserInfo valueForKey:@"license"])
//            {
//                
//                NSLog(@"%@",[dictUserInfo valueForKey:@"license"]);
//            }
//            else
//            {
//                [self justShowMessage:@"车牌号码不能为空,请到车辆设置页面去补充" title:@"注意"];
//                [Switch setOn:NO];
//                return;
//            }
        }
        else
        {
            [self justShowMessage:@"车牌号码不能为空,请到车辆设置页面去补充" title:@"注意"];
            [Switch setOn:NO];
            return;
        }
        if (Switch.on) {
            strCarInspection=@"1";
        }
        else
        {
            strCarInspection=@"0";
        }
        
    }
    else if(Switch.tag==1)
    {
        if (Switch.on) {
            strlicenseInspection=@"1";
        }
        else
        {
            strlicenseInspection=@"0";
        }
        
    }
    else if(Switch.tag==2)
    {
//        NSLog(@"DICT_CAR_INFO%@",[[NSUserDefaults standardUserDefaults] objectForKey:DICT_CAR_INFO]);
//        NSDictionary *dictUserInfo=[[NSUserDefaults standardUserDefaults] dictionaryForKey:DICT_CAR_INFO];
        if (hasCarInfo==YES)
        {
//            if ([dictUserInfo valueForKey:@"firstdate"])
//            {
//                
//                NSLog(@"%@",[dictUserInfo valueForKey:@"firstdate"]);
//            }
//            else
//            {
//                [self justShowMessage:@"车辆初登日期不能为空,请到车辆设置页面去补充" title:@"注意"];
//                [Switch setOn:NO];
//                return;
//            }
        }
        else
        {
            [self justShowMessage:@"车辆初登日期不能为空,请到车辆设置页面去补充" title:@"注意"];
            [Switch setOn:NO];
            return;
        }
        
        if (Switch.on) {
            strTravelTax=@"1";
        }
        else
        {
            strTravelTax=@"0";
        }
    
    }
}
-(void)setRemindInsurance:(id)sender
{
    UISwitch *Switch=(UISwitch *)sender;
   // NSString *strTag=[NSString stringWithFormat:@"%d",Switch.tag];
    //[self justShowMessage:strTag title:@""];
    if(Switch.tag==0)
    {
        if (Switch.on) {
            strClaimsProgress=@"1";
        }
        else
        {
            strClaimsProgress=@"0";
        }
        
    }
    else if(Switch.tag==1)
    {
        if (Switch.on) {
            strPolicyRenewal=@"1";
        }
        else
        {
            strPolicyRenewal=@"0";
        }
        
    }
    else if(Switch.tag==2)
    {
        if (Switch.on) {
            strServiceAppointment=@"1";
        }
        else
        {
            strServiceAppointment=@"0";
        }
    }
    else if(Switch.tag==3)
    {
        if (Switch.on) {
            strPreferential=@"1";
        }
        else
        {
            strPreferential=@"0";
        }
    }
    else if(Switch.tag==4)
    {
        if (Switch.on) {
            strSeckill=@"1";
        }
        else
        {
            strSeckill=@"0";
        }
    }
}

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    
}

- (void)viewDidUnload
{
    [super viewDidUnload];
    // Release any retained subviews of the main view.
}

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
    return (interfaceOrientation == UIInterfaceOrientationPortrait);
}

-(void)dealloc
{
    [arrCar release];
    [arrInsurance release];
    [arrSetListData release];
    [TableViewCar release];
    [TableViewInsurance release];
    [super dealloc];
}

@end
